﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace Planetwork.GetImage
{
    public partial class GetImage : System.Web.UI.Page
    {
        static string conStr = ConfigurationManager.AppSettings["conStr"];
        SqlConnection mycon = new SqlConnection(conStr);
        protected void Page_Load(object sender, EventArgs e)
        {
            //Default.aspx
            if (Request.QueryString["imgID"] != null)
            {
                string sql = "select ImageData from DefaultImage where ID=" + Request.QueryString["imgID"].ToString();
                SqlDataAdapter mydat = new SqlDataAdapter(sql, mycon);
                DataSet myds = new DataSet();
                mycon.Open();
                try
                {
                    mydat.Fill(myds);
                    mycon.Close();
                    byte[] buffer = (byte[])myds.Tables[0].Rows[0][0];
                    if (buffer.Length > 0)
                    {
                        Response.Clear();
                        Response.OutputStream.Write(buffer, 0, buffer.Length);
                        Response.End();
                    }
                }
                catch
                {
                    mycon.Close();
                }
            }

            //ViewPics.aspx
            if (Request.QueryString["GigPicsImg"] != null)
            {
                string sql = "select ImageData from Images where ID=" + Request.QueryString["GigPicsImg"].ToString();
                SqlDataAdapter mydat = new SqlDataAdapter(sql, mycon);
                DataSet myds = new DataSet();
                mycon.Open();
                try
                {
                    mydat.Fill(myds);
                    mycon.Close();
                    byte[] buffer = (byte[])myds.Tables[0].Rows[0][0];
                    if (buffer.Length > 0)
                    {
                        Response.Clear();
                        Response.OutputStream.Write(buffer, 0, buffer.Length);
                        Response.End();
                    }
                }
                catch
                {
                    mycon.Close();
                }
            }
        }
    }
}